package chapter10;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-22 上午11:30
 */
public class ReflectTest2 {
    private static final Logger LOGGER = LoggerFactory.getLogger(ReflectTest2.class);

    public static void main(String[] args) {
        Class<?> cls = TestBook.class;
        try {
            Object object = cls.newInstance();
            Field titleField = cls.getDeclaredField("title");
            titleField.setAccessible(true);
            titleField.set(object, "test");
            LOGGER.info(String.valueOf(titleField.get(object)));
        } catch (InstantiationException | IllegalAccessException | NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
}
